﻿//------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
//------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.Text;

namespace Microsoft.ResourceManagement.Samples.ResourceManagementClient.WSEnumerate
{
    /// <summary>
    /// This class encapsulates a WS-Enumeration EnumerateRequest.
    /// Please read the spec http://www.w3.org/Submission/WS-Enumeration/
    /// 
    /// A client sends an EnumerateRequest to the Enumerate endpoint to receive
    /// an EnumerationContext in the EumerateResponse.
    /// 
    /// A client then uses the EnumerationContext to Pull data from the server.
    /// </summary>
    [XmlRoot(ElementName = "Enumerate", Namespace = Constants.NamespaceWSEnumeration)]
    public class EnumerateRequest
    {
        private DateTime expires;
        private EnumerateFilter filter;
        private string[] selectionField;
        private Sorting sortingField;

        /// <summary>
        /// Default constructor
        /// </summary>
        public EnumerateRequest()
        {
            this.Expires = DateTime.Now.AddMinutes(Settings.Default.WsEnumerationDefaultExpiresAdd);
            this.Filter = new EnumerateFilter();
        }

        
        /// <summary>
        /// The requested expriation time of the enumeration context.
        /// </summary>
        [XmlElement(ElementName = "Expires", Type = typeof(DateTime))]
        public DateTime Expires
        {
            get
            {
                return this.expires;
            }
            set
            {
                this.expires = value;
            }
        }
        
        /// <summary>
        /// The filter describes how the server should select the objects.
        /// </summary>
        [XmlElement(ElementName = "Filter", Type = typeof(EnumerateFilter))]
        public EnumerateFilter Filter
        {
            get
            {
                return this.filter;
            }
            set
            {
                this.filter = value;
            }
        }

        [XmlElement(Namespace = "http://schemas.microsoft.com/2006/11/ResourceManagement")]
        public string[] Selection
        {
            get
            {
                return this.selectionField;
            }
            set
            {
                this.selectionField = value;
            }
        }

        [XmlElement(Namespace = "http://schemas.microsoft.com/2006/11/ResourceManagement")]
        public Sorting Sorting
        {
            get
            {
                return this.sortingField;
            }
            set
            {
                this.sortingField = value;
            }
        }

    }

    [XmlType(TypeName="EnumerateFilter")]
    public class EnumerateFilter
    {
        public EnumerateFilter()
        {
            this.Dialect = Constants.WSEnumerationDefaultFilterDialect;
            this.Filter = String.Empty;
        }
        private String dialect;
        /// <summary>
        /// The dialect describes the format of the filter.  By default we use a xpath-like language.
        /// </summary>
        [XmlAttribute(AttributeName = "Dialect", Namespace = Constants.NamespaceWSEnumeration)]
        public String Dialect
        {
            get
            {
                return this.dialect;
            }
            set
            {
                this.dialect = value;
            }
        }
        private String filter;
        /// <summary>
        /// The filter is the query the server uses to select the resulting objects.
        /// Think of the filter as the WHERE clause in a SQL SELECT query.
        /// </summary>
        [XmlText(Type = typeof(string))]
        public String Filter
        {
            get
            {
                return this.filter;
            }
            set
            {
                this.filter = value;
            }
        }
    }
}
